perm filename PERMS.PPL[VLI,LSP] blob
sn#382045 filedate 1978-09-08 generic text, type T, neo UTF8
(TML)
let cons x y = x.y ;;
letrec concat x = (null x => [] | (hd x)@(concat (tl x)));;
letrec perms n =
if n=0 then [[]] else
insert n (perms (n-1)) where
insert n x = concat (map (put n) x) whererec
put n x = if null x then [[n]]
else (n.x).(map (cons (hd x))
(put n (tl x))) ;;
letrec p x = if null x then [[]] else f x
whererec f (a.y) = (map (cons a) (p y)) @ g(y @ [a])
and g y = if x=y then [] else f y ;;